import pandas as pd
import matplotlib.pyplot as plt
import seaborn
from sklearn.cluster import KMeans
from sklearn.preprocessing import LabelEncoder
from sklearn.ensemble import GradientBoostingClassifier
from sklearn import metrics
from sklearn import model_selection

data_set = pd.read_csv('employee_data.csv')
# # group by number_project
# number_projects = data_set.groupby('number_project').count()
# print(number_projects)
# plt.bar(number_projects.index.values, number_projects['satisfaction_level'])
# plt.xlabel('number_projects')
# plt.ylabel('satisfaction_level')
# plt.show()
#
# # time_spend_company
# time_spend_company = data_set.groupby('time_spend_company').count()
# print(time_spend_company)
# plt.bar(time_spend_company.index.values, time_spend_company['satisfaction_level'])
# plt.xlabel('time_spend_company')
# plt.ylabel('satisfaction_level')
# plt.show()
#
# # Work_accident
# Work_accident = data_set.groupby('Work_accident').count()
# print(Work_accident)
# plt.bar(Work_accident.index.values, Work_accident['satisfaction_level'])
# plt.xlabel('Work_accident')
# plt.ylabel('number of accidents')
# plt.show()
#
# # Departments
# Departments = data_set.groupby('Departments').count()
# print(Departments)
# plt.bar(Departments.index.values, Departments['satisfaction_level'])
# plt.xlabel('Departments')
# plt.ylabel('Number of departments')
# plt.show()
#
# # salary
# salary = data_set.groupby('salary').count()
# print(salary)
# plt.bar(salary.index.values, salary['satisfaction_level'])
# plt.xlabel('Salary')
# plt.ylabel('Number of employees')
# plt.show()
#
# features = ['number_project', 'time_spend_company', 'Work_accident', 'Departments', 'salary']
# for i, j in enumerate(features):
#     plt.subplot(3, 2, i + 1)
#     seaborn.countplot(x=j, data=data_set)
#     plt.subplots_adjust(hspace=1.0)
#     plt.xticks(rotation=90)
# plt.show()
#

# left_data = data_set[['satisfaction_level', 'last_evaluation']][data_set.left == 1]
# kmeans = KMeans(n_clusters=3).fit(left_data)
# left_data['label'] = kmeans.labels_
# print(left_data)
# plt.scatter(left_data['satisfaction_level'], left_data['last_evaluation'], c=left_data['label'])
# plt.xlabel('satisfaction_level')
# plt.ylabel('last_evaluation')
# plt.show()

# Preprocessing
le = LabelEncoder()
data_set['Departments'] = le.fit_transform(data_set['Departments'])
data_set['salary'] = le.fit_transform(data_set['salary'])
print(data_set)

X = data_set[['satisfaction_level', 'last_evaluation', 'number_project', 'average_montly_hours', 'time_spend_company',
              'Work_accident', 'promotion_last_5years', 'Departments', 'salary']]
y = data_set['left']

X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y, test_size=0.25)
gtc = GradientBoostingClassifier()
gtc.fit(X_train, y_train)
y_pred = gtc.predict(X_test)
y_score = metrics.accuracy_score(y_test, y_pred)
print(y_score)



